/*
 * @Author: liyongxuan
 * @Date: 2018-1-10 10:37:42
 * @Last Modified by: liyongxuan
 * @Last Modified time: 2018-1-10 10:37:42
 * @description：项目管理-拟投资-项目详情编辑
 */
<template>
  <div>
    <div class="ca-title">
        <el-col :span="3" class="float-right" v-if="itemId!='-1'&&showBtn">
            <el-button size="small" type="primary" @click="checkForm">保存</el-button>
            <el-button size="small" @click="$emit('close')">取消</el-button>
        </el-col>
        <h3>项目详情</h3>
    </div>
    <el-form ref="form" class="ca-m-t-20" :model="proDetailEdit" label-width="150px" :rules='rules'>
      <el-row>
          <el-col :span="7" :offset="1">
              <el-form-item label="项目来源：" label-width="110px">
                  <el-input v-model="proDetailEdit.itemSource" :maxlength="50" type="text"></el-input>                
              </el-form-item>
          </el-col>
          <!-- <el-col :span="7">
              <el-form-item label="项目轮次：">
                <el-select :clearable="true" class="width100" v-model="proDetailEdit.prostatus" placeholder="请选择" >
                    <el-option v-for="item in initView.prostatus" :label="item.name" :value="item.id" :key="item.id">
                    </el-option>
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="7" :offset="1">
              <el-form-item label="证券代码：" label-width="90px">
                  <el-input :maxlength="50" v-model="proDetailEdit.securityCode" type="text"></el-input>                  
              </el-form-item>
          </el-col> -->
          <el-col :span="7">
            <el-form-item label="初次接触时间：">
                <el-date-picker v-model="proDetailEdit.firstContact" class="width100" format="yyyy-MM-dd" type="date" placeholder="选择日期" ></el-date-picker>                
            </el-form-item>
          </el-col>
          <el-col :span="7" :offset="1">
            <el-form-item label="最近接触时间：" label-width="110px">
                <el-date-picker v-model="proDetailEdit.lastUpdate" class="width100" format="yyyy-MM-dd" type="date" placeholder="选择日期" ></el-date-picker>                
            </el-form-item>
          </el-col>
      </el-row>
      <el-row>
          <el-col :span="7" :offset="1">
              <el-form-item label="创始人：" label-width="110px">
                  <el-input v-model="proDetailEdit.founder" :maxlength="50" type="text"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="公司成立时间：">
                <el-date-picker v-model="proDetailEdit.registrationTime" class="width100" format="yyyy-MM-dd" type="date" placeholder="选择日期" ></el-date-picker>                
            </el-form-item>
          </el-col>
          <el-col :span="7" :offset="1">
              <el-form-item label="企业性质：" label-width="110px">
                <el-select :clearable="true" class="width100" v-model="proDetailEdit.companyNature" placeholder="请选择" >
                    <el-option v-for="item in initView.nature" :label="item.name" :value="item.id" :key="item.id">
                    </el-option>
                </el-select>
              </el-form-item>
          </el-col>
      </el-row>
      <el-row>
          <el-col  :span="7" :offset="1">
              <el-form-item label="注册资本：" label-width="110px" prop='registeredCapital'>
                <el-input type="number" :maxlength="20" v-model="proDetailEdit.registeredCapital">
                    <template slot="append">万元</template>
                </el-input>
              </el-form-item>
          </el-col>
          <el-col :span="7">
              <el-form-item label="实收资本：" prop='paidInCapital'>
                <el-input type="number" :maxlength="20" v-model="proDetailEdit.paidInCapital">
                    <template slot="append">万元</template>
                </el-input>
              </el-form-item>
          </el-col>
          <el-col :span="7" :offset="1">
              <el-form-item label="股东人数：" label-width="110px">
                <el-input type="number" :maxlength="20" v-model="proDetailEdit.shareholderNum"></el-input>
              </el-form-item>
          </el-col>
      </el-row>
        <el-row>
          <el-col :span="7" :offset="1">
              <el-form-item label="基金外派监事：" label-width="110px">
                  <el-input :maxlength="50" type="text" v-model="proDetailEdit.fundExternalSupervisor"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="公司电话：">
                <el-input type="text" :maxlength="20" v-model="proDetailEdit.companyTel"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="7" :offset="1">
              <el-form-item label="投资角色：" label-width="110px">
                <el-select :clearable="true" class="width100" placeholder="请选择" v-model="proDetailEdit.investRole">
                    <el-option v-for="item in initView.investRole" :label="item.name" :value="item.id" :key="item.id">
                    </el-option>
                </el-select>
              </el-form-item>
          </el-col>
      </el-row>
      <!-- 改 -->
        <el-row>
          <el-col :span="7" :offset="1">
              <el-form-item label="基金外派董事：" label-width="110px">
                <el-input type="text" :maxlength="20" v-model="proDetailEdit.fundAssigningDirectors"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="投后估值：" prop='paidInCapital'>
                <el-input type="number" :maxlength="20" v-model="proDetailEdit.postValuation">
                    <template slot="append">万元</template>
                </el-input>
              </el-form-item>
          </el-col>
          <el-col :span="7" :offset="1">
              <el-form-item label="投前估值：" label-width="110px" prop='paidInCapital'>
                <el-input type="number" :maxlength="20" v-model="proDetailEdit.preValuation">
                    <template slot="append">万元</template>
                </el-input>
              </el-form-item>
          </el-col>
      </el-row>
      <el-row>
        <el-col :span="7" :offset="1">
              <el-form-item label="项目轮次：" label-width="110px">
                <el-select :clearable="true" class="width100" v-model="proDetailEdit.prostatus" placeholder="请选择" >
                    <el-option v-for="item in initView.prostatus" :label="item.name" :value="item.id" :key="item.id">
                    </el-option>
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="15">
              <el-form-item label="子基金项目管理人员：" label-width="155px">
                <el-input type="text" :maxlength="20" v-model="proDetailEdit.subFundManager"></el-input>
              </el-form-item>
          </el-col>
      </el-row>
      <el-row>
          <el-col :span="23" :offset="1">
            <!-- <csRegion :address='officeAddress' ref="officeAddress" :title="'办公地址：'" :labelWidth="'110px'"></csRegion> -->
            <csRegion :address='registeredAddress' ref="registeredAinvestmentWayddress" :title="'注册地址'" :labelWidth="'110px'"></csRegion>
          </el-col>
      </el-row>
      <el-row>
          <el-col :span="22" :offset="1">
              <el-form-item label="投资方式：" label-width="110px">
                <el-input v-model="proDetailEdit.investmentWay" :maxlength="3000" type="textarea" :rows="4"></el-input>                                                
              </el-form-item>
          </el-col>
      </el-row>
      <el-row>
          <el-col :span="22" :offset="1">
              <el-form-item label="估值方式：" label-width="110px">
                <el-input v-model="proDetailEdit.valuationMethod" :maxlength="3000" type="textarea" :rows="4"></el-input>                                                
              </el-form-item>
          </el-col>
      </el-row>
      <el-row>
          <el-col :span="22" :offset="1">
              <el-form-item label="联合投资：" label-width="110px">
                <el-input v-model="proDetailEdit.jointInvestment" :maxlength="3000" type="textarea" :rows="4"></el-input>                                                
              </el-form-item>
          </el-col>
      </el-row>
      <el-row>
          <el-col :span="22" :offset="1">
              <el-form-item label="备注：" label-width="110px">
                <el-input v-model="proDetailEdit.remark" :maxlength="3000" type="textarea" :rows="4"></el-input>                                                
              </el-form-item>
          </el-col>
      </el-row>
      <el-row>
          <el-col :span="22" :offset="1">
              <el-form-item label="其他：" label-width="110px">
                <el-input v-model="proDetailEdit.other" :maxlength="3000" type="textarea" :rows="4"></el-input>                                                
              </el-form-item>
          </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script type="text/ecmascript-6">
    import {api} from '../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import { addRemind } from '__service/utils';
    export default {
        data() {
            var validateNumber = (rule, value, callback) => {
                var reg = /^\d{1,10}(\.\d{1,6})?$/;
                if (value !== '' && value !== null && !reg.test(value)) {
                    callback(new Error('数字范围在小数点前十位,小数点后六位'));
                } else {
                    callback();
                }
            };
            return {
                initView: {
                    nature: this.$store.state.user.dictionaryMap.nature,//企业性质
                    prostatus: this.$store.state.user.dictionaryMap.prostatus,//项目轮次
                    investRole: this.$store.state.user.dictionaryMap.investRole,//投资角色
                },
                rules: {
                    registeredCapital: [{ validator: validateNumber, trigger: 'blur' }],
                    paidInCapital: [{ validator: validateNumber, trigger: 'blur' }],
                }
            }
        },
        watch: {
            registeredAddress: {
                handler: function (registeredAddress) {
                    this.region = []
                    registeredAddress.businessId = this.itemId
                    this.region.push(registeredAddress, this.officeAddress)
                    this.$emit('region', this.region);
                },
                deep: true
            },
            // officeAddress: {
            //     handler: function (officeAddress) {
            //         this.region = []
            //         officeAddress.businessId = this.itemId
            //         this.region.push(this.registeredAddress, officeAddress)
            //         this.$emit('region', this.region);
            //     },
            //     deep: true
            // },
        },
        props: {
          proDetailEdit: {
            type: Object,
            default: function () {
              return {}
            }
          },
          registeredAddress: {
              type: Object,
              default: function () {
                    return {
                        id: '',
                        businessId: this.itemId,
                        province: '',
                        city: '',
                        district: '',
                        businessType: 1,
                        registrationDetailed: ''
                    }
              }
          },
          // officeAddress: {
          //     type: Object,
          //     default: function () {
          //           return {
          //               id: '',
          //               businessId: this.itemId,
          //               province: '',
          //               city: '',
          //               district: '',
          //               businessType: 2,
          //               registrationDetailed: ''
          //           }
          //     }
          // },
          itemId: {
              type: String,
              default: ''
          },
            showBtn: {
                type: Boolean,
                default: true
            }
        },
        mounted() {
            this.$refs.registeredAinvestmentWayddress.inview(this.registeredAddress)
            // this.$refs.officeAddress.inview(this.officeAddress)
        },
        methods: {
            // 表单验证
            checkForm() {
                this.$refs.form.validate(valid => {
                    if (valid) {
                        this.putItemQuasiEntityDetails()
                    } else {
                        return false;
                    }
                });
            },
            // 编辑拟投资项目详情
            async putItemQuasiEntityDetails() {
                let query = {
                    'companyNature': this.proDetailEdit.companyNature || '',
                    'companyTel': this.proDetailEdit.companyTel || '',
                    'founder': this.proDetailEdit.founder || '',
                    'id': this.proDetailEdit.id || '',
                    'investAmount': this.proDetailEdit.investAmount || '',
                    'itemId': this.proDetailEdit.itemId || '',
                    'itemSource': this.proDetailEdit.itemSource || '',
                    // 'officeAddress': this.proDetailEdit.officeAddress || '',
                    'paidInCapital': this.proDetailEdit.paidInCapital || '',
                    'prostatus': this.proDetailEdit.prostatus || '',// 项目轮次
                    'firstContact': this.proDetailEdit.firstContact,// 首次接触时间
                    'lastUpdate': this.proDetailEdit.lastUpdate,// 最近接触时间
                    'investRole': this.proDetailEdit.investRole || '',//投资角色
                    'postValuation': this.proDetailEdit.postValuation || '',//投后估值
                    'preValuation': this.proDetailEdit.preValuation || '',//投前估值
                    'subFundManager': this.proDetailEdit.subFundManager || '',//投前估值
                    'fundAssigningDirectors': this.proDetailEdit.fundAssigningDirectors || '',//基金外派董事
                    'fundExternalSupervisor': this.proDetailEdit.fundExternalSupervisor || '',//基金外派监事
                    'investmentWay': this.proDetailEdit.investmentWay || '',//投资方式
                    'valuationMethod': this.proDetailEdit.valuationMethod || '',//估值方式
                    'jointInvestment': this.proDetailEdit.jointInvestment || '',//联合投资
                    'other': this.proDetailEdit.other || '',//其他
                    'registeredAddress': this.proDetailEdit.registeredAddress || '',
                    'registeredCapital': this.proDetailEdit.registeredCapital || '',
                    'region': [],
                    'registrationTime': this.proDetailEdit.registrationTime || '',
                    'remark': this.proDetailEdit.remark || '',
                    'securityCode': this.proDetailEdit.securityCode || '',
                    'shareholderNum': this.proDetailEdit.shareholderNum || ''
                }
                //地区处理
                if (this.registeredAddress.province) {
                    this.registeredAddress.businessId = this.itemId
                    this.registeredAddress.businessType = 1
                    query.region.push(this.registeredAddress)
                }
                // if (this.officeAddress.province) {
                //     this.officeAddress.businessId = this.itemId
                //     this.officeAddress.businessType = 2
                //     query.region.push(this.officeAddress)
                // }
                const {resCode} = await apiHttp(api.PUT_ITEM_QUASI_ENTITY_DETAILS, query)
                if (resCode === STATUS_HTTP_SUCCESS) {
                    // 添加小红点
                    await addRemind({
                        dataId: this.proDetailEdit.itemId || '', // 业务id
                        dataTab: 0, // tab页顺序 head 也为0
                        dataType: 1, // 1拟投资项目,2已投资项目,3母基金,4拟设立基金,5已设立基金,6客户,7潜在项目
                    });
                    // 根据第三方组件来调用 父组件中定义的方法 重新获取小红点
                    this.$root.Dot.$emit('getDotList');
                    this.$emit('close')
                }
            }
        },
        components: {
            csRegion: require('__components/region'),//地区
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.float-right{
    float: right;
}
.width100{
    width: 100%
}
</style>
